import { useState } from 'react'
export default () => {

  //count：声明的变量名称，setCount用于修改count的方法，以set开头
  const [count, setcount] = useState(10)
  const [zhoukai] = useState('帅哥');

  const [obj, setObj] = useState({
    username: '张三',
    age: 18
  })

  const clickBtn = () => {
    setcount(count + 1);

    setObj((val) => {
      //val为obj的值
      return {
        ...val,
        age: val.age + 1
      };
    });
  }

  return (
    <>
      <h1>app</h1>
      <p> {count}</p>
      <p>{zhoukai}</p>
      <p>{obj.username}-{obj.age}</p>
      <button onClick={clickBtn}>+1</button>
    </>
  )
}